package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.AdsMsg;
import com.ruoyi.system.service.IAdsMsgService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 广告信息Controller
 * 
 * @author shawu
 * @date 2024-08-15
 */
@RestController
@RequestMapping("/system/ads")
public class AdsMsgController extends BaseController
{
    @Autowired
    private IAdsMsgService adsMsgService;

    /**
     * 查询广告信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:ads:list')")
    @GetMapping("/list")
    public TableDataInfo list(AdsMsg adsMsg)
    {
        startPage();
        List<AdsMsg> list = adsMsgService.selectAdsMsgList(adsMsg);
        return getDataTable(list);
    }

    /**
     * 导出广告信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:ads:export')")
    @Log(title = "广告信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AdsMsg adsMsg)
    {
        List<AdsMsg> list = adsMsgService.selectAdsMsgList(adsMsg);
        ExcelUtil<AdsMsg> util = new ExcelUtil<AdsMsg>(AdsMsg.class);
        util.exportExcel(response, list, "广告信息数据");
    }

    /**
     * 获取广告信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:ads:query')")
    @GetMapping(value = "/{adId}")
    public AjaxResult getInfo(@PathVariable("adId") Long adId)
    {
        return success(adsMsgService.selectAdsMsgByAdId(adId));
    }

    /**
     * 新增广告信息
     */
    @PreAuthorize("@ss.hasPermi('system:ads:add')")
    @Log(title = "广告信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AdsMsg adsMsg)
    {
        return toAjax(adsMsgService.insertAdsMsg(adsMsg));
    }

    /**
     * 修改广告信息
     */
    @PreAuthorize("@ss.hasPermi('system:ads:edit')")
    @Log(title = "广告信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AdsMsg adsMsg)
    {
        return toAjax(adsMsgService.updateAdsMsg(adsMsg));
    }

    /**
     * 删除广告信息
     */
    @PreAuthorize("@ss.hasPermi('system:ads:remove')")
    @Log(title = "广告信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{adIds}")
    public AjaxResult remove(@PathVariable Long[] adIds)
    {
        return toAjax(adsMsgService.deleteAdsMsgByAdIds(adIds));
    }
}
